﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;

namespace TSNPro.Helper
{
    public static class ResourceHelper
    {

        public static JObject ReadEmbeddedJObject(string path)
        {
            string content=ReadEmbeddedResource(path);
            return JObject.Parse(content);
        }

        // 读取嵌入的资源
        public static string ReadEmbeddedResource(string path)
        {
            // 获取程序集
            Assembly assembly = Assembly.GetExecutingAssembly();

            // 获取嵌入资源的完整名称
            string resourceName=path.Replace(":", "TSNPro").Replace("/",".");

            // 使用 GetManifestResourceStream 获取文件流
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                if (stream != null)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        // 读取文件内容
                        string content = reader.ReadToEnd();
                        return content;
                    }
                    
                }
                else
                {
                    return null; 
                }
            }
        }
    }
}
